Installation
First, let’s install the necessary packages to run this tutorial.fastdup- Analyze issues in the dataset.datasets- Pull datasets from Hugging Face Datasets.
📘 Info There are over 50,000 openly available datasets on Hugging Face Datasets. Some datasets are gated and can only be downloaded if you have a user credential.
Load Dataset
The Hugging Facedatasets package provides an easy interface to load any datasets from the Hugging Face platform. On top of the package, fastdup provides a wrapper class FastdupHFDataset as a connector to ensure the datasets package works seamlessly within fastdup.
The FastdupHFDataset class works the same way as the load_dataset method. You can import the wrapper class and specify the name of the Hugging Face Datasets repository as the first argument.
In this example, we load the Tiny ImageNet dataset which contains 100,000 images of 200 classes (500 for each class) downsized to 64×64 colored images. Each class has 500 training images, 50 validation images, and 50 test images.
In the following code, we load the train split of the Tiny ImageNet dataset.
👍 Tip Optional parameters for theNow, let’s inspect theFastdupHFDatasetclass:See implementation for details.
split- Which split to download. Default:'train'.img_key- The key value for the dataset column containing images. Default:'image'.label_key- The key value for the dataset column containing labels. Default:'label'.cache_dir- Where to cache the downloaded dataset. Default:'/root/.cache/huggingface/datasets/'jpg_save_dir- Which folder to store thejpgimages. Default:'jpg_images'reconvert_jpg- Flag to force reconversion of images from.parquetto.jpg. Default:False
dataset object.
PIL image of the first element.
📘 Info You can also confirm the image and label of the first element by heading to the dataset page.
Run fastdup
Once loaded, we can now analyze the dataset in fastdup by passing in 2 properties ofdataset into fastdup:
dataset.img_dir- Returns the folder directory where the jpg images are saved.dataset.annotations- Returns aDataFrameof image and class labels.
dataset.img_dir and dataset.annotations as arguments.
Duplicates
Let’s visualize the duplicates in a gallery.similaritymethod.
distance score. A distance of 1.0 is an exact copy, and vice versa.
Outliers
Mislabels
Wrap Up
That’s it! We’ve just conveniently surfaced many issues with this dataset by running fastdup. By taking care of dataset quality issues, we hope this will help you train better models. Questions about this tutorial? Reach out to us on our Slack channel!VL Profiler - A faster and easier way to diagnose and visualize dataset issues
The team behind fastdup also recently launched VL Profiler, a no-code cloud-based platform that lets you leverage fastdup in the browser. VL Profiler lets you find:- Duplicates/near-duplicates.
- Outliers.
- Mislabels.
- Non-useful images.
👍 Free Usage Use VL Profiler for free to analyze issues on your dataset with up to 1,000,000 images. Get started for free.Not convinced yet? Interact with a collection of datasets like ImageNet-21K, COCO, and DeepFashion here. No sign-ups needed.